const axios = require("axios");
const { userSessions } = require("../utils/userInfo");
const logger = require("../utils/loggers");
const service = axios.create({
  baseURL: "http://10.100.70.33:18097",
  timeout: 20000,
});
// 请求响应
service.interceptors.request.use(
  (config) => {
    console.log("config======", config);
    logger.info(`请求相应数据：${JSON.stringify(config.data)}`);
    if (config.data && config.data.hasOwnProperty("acceptToken")) {
      config.headers["acceptToken"] = config.data.acceptToken;
      config.headers["Accept-Token"] = config.data.acceptToken;
    }
    if (config.data && config.data.hasOwnProperty("refreshTokenCSX")) {
      config.headers["refreshToken"] = config.data.refreshTokenCSX;
    }
    if (config.data && config.data.hasOwnProperty("authorization")) {
      config.headers["authorization"] = config.data.authorization;
    }
    if (config.data && config.data.hasOwnProperty("blade-Auth")) {
      config.headers["blade-Auth"] = config.data.bladeAuth;
    }

    return config;
  },
  (error) => {
    return Promise.reject(error);
  }
);

service.interceptors.response.use(
  (response) => {
    return response.data;
  },
  (error) => {
    return Promise.reject(error);
  }
);

module.exports = service;
